package com.yanftch.stopcoding.config;

import com.yanftch.stopcoding.request.*;

import java.awt.*;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.stream.Stream;

public class DefaultConfig {
    /**
    * 调试模式设置为true
    */
    public static boolean DEBUG = false;
    public static String DEFAULT_ERROR_MESSAGE = "接口失败,请联系开发者~(以下为随机文案)";

    public static final String BING_RANDOM_URL = "https://bing.img.run/rand_1366x768.php";
    // 默认提醒间隔
    public static Integer DEFAULT_PERIOD_MINUTES = 45;
    // 默认提醒单位
    public static TimeUnit DEFAULT_PERIOD_UNIT = TimeUnit.MINUTES;
    public static String DEFAULT_DIALOG_TITLE = "休息一下吧~保护颈椎从我做起~";
    public static String DEFAULT_IMAGE_SRC = ImageSourceEnum.BING.description;
    public static String DEFAULT_TEXT_SRC = TextSourceEnum.WEIBO.description;



    /**
    * 基本数据
    */
    public enum ImageSourceEnum {
        // bing 壁纸接口：https://apifox.com/apidoc/shared-faff130e-7aa3-42da-9f93-574b16c8acda/api-30781027
        BING(0, "Bing", "https://api.timelessq.com/bing/random"), // https://bing.img.run/rand_1366x768.php 这个链接会存在 SSL 问题，暂时先不用了
        MEITNV(1, "美图美女", "https://cdn.seovx.com/?mom=302"),
        ERCIYUAN(2, "二次元", "https://cdn.seovx.com/d/?mom=302"),
        GUFENGMEINV(3, "古风美女", "https://cdn.seovx.com/ha/?mom=302"),
        COPPLAY(4, "Cosplay", "https://imgapi.cn/cos.php"),
        SUIJI(5, "随机壁纸", "https://imgapi.cn/api.php");

        private static Map<String, ImageSourceEnum> stringToEnum = new HashMap<>();

        static {
            for (ImageSourceEnum act : values()) {
                stringToEnum.put(act.toString(), act);
            }
        }

        public final int index;
        public final String description;
        public final String url;

        ImageSourceEnum(int index, String description, String url) {
            this.index = index;
            this.description = description;
            this.url = url;
        }

        public static ImageSourceEnum valueOf(int index) {
            return Stream.of(ImageSourceEnum.values()).filter(imageSrcType -> index == imageSrcType.index).findFirst().orElseThrow(NullPointerException::new);
        }

        @Override
        public String toString() {
            return description;
        }

        public static ImageSourceEnum fromString(String type) {
            return stringToEnum.get(type);
        }
    }

    public enum TextSourceEnum {
        WEIBO(0, "微博热搜", new WeiBoRequest()), BAIDU(1, "百度热搜", new BaiduHotRequest()), ZHIHU(2, "知乎热搜", new ZhihuHotRequest()), TOUTIAO(3, "头条热搜", new TouTiaoHotRequest()), GAOXIAO(4, "搞笑文案", new TextGaoxiao()), WEIMEI(5, "唯美文案", new TextWeimei());

        private static Map<String, TextSourceEnum> stringToEnum = new HashMap<>();

        static {
            for (TextSourceEnum act : values()) {
                stringToEnum.put(act.toString(), act);
            }
        }

        public final int index;
        public final String description;
        public final Request request;

        TextSourceEnum(int index, String description, Request request) {
            this.index = index;
            this.description = description;
            this.request = request;
        }

        public static TextSourceEnum valueOf(int index) {
            return Stream.of(TextSourceEnum.values()).filter(imageSrcType -> index == imageSrcType.index).findFirst().orElseThrow(NullPointerException::new);
        }

        @Override
        public String toString() {
            return description;
        }

        public static TextSourceEnum fromString(String type) {
            return stringToEnum.get(type);
        }
    }

    public static boolean canLink(String text) {
        return TextSourceEnum.WEIBO.description.equals(text) || TextSourceEnum.BAIDU.description.equals(text) || TextSourceEnum.ZHIHU.description.equals(text) || TextSourceEnum.TOUTIAO.description.equals(text);
    }
}
